package com.yipei.business.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.yipei.business.domain.MlFlashNews;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yipei.common.annotation.Log;
import com.yipei.common.core.controller.BaseController;
import com.yipei.common.core.domain.AjaxResult;
import com.yipei.common.enums.BusinessType;
import com.yipei.business.domain.MlHeadlinesNews;
import com.yipei.business.service.IMlHeadlinesNewsService;
import com.yipei.common.utils.poi.ExcelUtil;
import com.yipei.common.core.page.TableDataInfo;

/**
 * 头条新闻Controller
 * 
 * @author yipei
 * @date 2024-12-21
 */
@Api(tags = "头条新闻", description = "头条新闻管理")
@RestController
@RequestMapping("/business/news")
public class MlHeadlinesNewsController extends BaseController
{
    @Autowired
    private IMlHeadlinesNewsService mlHeadlinesNewsService;

    /**
     * 查询头条新闻列表
     */
    @ApiOperation("头条新闻获取数据")
    //@PreAuthorize("@ss.hasPermi('business:news:list')")
    @GetMapping("/list")
    public TableDataInfo list(MlHeadlinesNews mlHeadlinesNews) throws IOException {
        startPage();
        List<MlHeadlinesNews> list = mlHeadlinesNewsService.selectMlHeadlinesNewsList(mlHeadlinesNews);
        return getDataTable(list);
    }

    /**
     * 导出头条新闻列表
     */
    //@PreAuthorize("@ss.hasPermi('business:news:export')")
    @Log(title = "头条新闻", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("头条新闻导出")
    public void export(HttpServletResponse response, MlHeadlinesNews mlHeadlinesNews)
    {
        List<MlHeadlinesNews> list = mlHeadlinesNewsService.selectMlHeadlinesNewsList(mlHeadlinesNews);
        ExcelUtil<MlHeadlinesNews> util = new ExcelUtil<MlHeadlinesNews>(MlHeadlinesNews.class);
        util.exportExcel(response, list, "头条新闻数据");
    }

    /**
     * 获取头条新闻详细信息
     */
    @ApiOperation("通过ID获取头条新闻数据")
    //@PreAuthorize("@ss.hasPermi('business:news:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mlHeadlinesNewsService.selectMlHeadlinesNewsById(id));
    }

    /**
     * 新增头条新闻
     */
    @ApiOperation("头条新闻新增数据")
    //@PreAuthorize("@ss.hasPermi('business:news:add')")
    @Log(title = "头条新闻", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MlHeadlinesNews mlHeadlinesNews)
    {
        return toAjax(mlHeadlinesNewsService.insertMlHeadlinesNews(mlHeadlinesNews));
    }

    /**
     * 修改头条新闻
     */
    @ApiOperation("头条新闻修改数据")
    //@PreAuthorize("@ss.hasPermi('business:news:edit')")
    @Log(title = "头条新闻", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MlHeadlinesNews mlHeadlinesNews)
    {
        return toAjax(mlHeadlinesNewsService.updateMlHeadlinesNews(mlHeadlinesNews));
    }

    /**
     * 删除头条新闻
     */
    @ApiOperation("头条新闻删除数据")
    //@PreAuthorize("@ss.hasPermi('business:news:remove')")
    @Log(title = "头条新闻", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mlHeadlinesNewsService.deleteMlHeadlinesNewsByIds(ids));
    }
}
